|
|
|
|
|
|
|
INSERT INTO BaseTable VALUES
('CUST01',
'Willingham & Associates',
'300.65',
'RETAIL',
'This is a comment'
);
INSERT INTO BaseTable VALUES
('CUST02',
'Parker & Parker',
'1000.29',
'WHOLESALE',
'This is another comment'
);
INSERT INTO BaseTable VALUES
('CUST03',
'Anchor, Smith, & Hocking',
'575.25',
'RETAIL',
'This is the last comment'
);
// now make a new table from the old one
SELECT * INTO CopyTable FROM BaseTable;
// select just some of the records
SELECT * INTO RetailTable FROM BaseTable
WHERE CustType='RETAIL';
// show results
SELECT * FROM BaseTable;
SELECT * FROM CopyTable;
SELECT * FROM RetailTable;
// eof |
|
|
|
|
|
|
|
|
As you can see from Figure 15.10, only the rows with WHERE CustType = 'RETAIL' are copied to the new table. |
|
|
|
|
|
|
|
|
You can also use the GROUP BY and HAVING clauses to limit and summarize data before copying to a new table. Let's modify the SQLVB07.SQV script to produce only one record for each customer type, with each new row containing the customer type and total balance for that type. Let's also order the records in descending order by customer balance. Let's rename the CustBalance field to Balance. The modifications to SQLVB07.SQV are shown in Listing 15.10. Make your changes, save and run the script, and compare your results to Figure 15.11. |
|
|
|
|
|